package cn.tianjindong.blog.pojo;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class BlogArticle {
	private Long id;

	private String title;// 文章标题

	private String summary;// 摘要

	private Long categoryId;// 文章分类ID

	private String source;// 文章来源，例如：CSDN 51CTO等

	private Date createtime;

	private Date updatetime;

	private Long visitNum;// 文章的访问量

	private Integer tab;// 标记位，标识当前文章是否公开，0表示私有，1表示公开，-1表示作废

	private Long managerId;// '当前文章创建的管理员'

	private String content;// 文章内容

	/**
	 * 数据库没有该字段
	 */
	private int commentNum;// 评论数

	private List<BlogTag> tagList;// 文章对应的标签

	private BlogArticleCategory category;// 文章对应的分类对象

	private static SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

	public Long getVisitNum() {
		return visitNum;
	}

	public void setVisitNum(Long visitNum) {
		this.visitNum = visitNum;
	}

	public BlogArticleCategory getCategory() {
		return category;
	}

	public void setCategory(BlogArticleCategory category) {
		this.category = category;
	}

	public List<BlogTag> getTagList() {
		return tagList;
	}

	public void setTagList(List<BlogTag> tagList) {
		this.tagList = tagList;
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title == null ? null : title.trim();
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary == null ? null : summary.trim();
	}

	public Long getCategoryId() {
		return categoryId;
	}

	public void setCategoryId(Long categoryId) {
		this.categoryId = categoryId;
	}

	public String getSource() {
		return source;
	}

	public void setSource(String source) {
		this.source = source == null ? null : source.trim();
	}

	public int getCommentNum() {
		return commentNum;
	}

	public void setCommentNum(int commentNum) {
		this.commentNum = commentNum;
	}

	public Date getCreatetime() {
		return createtime;
	}

	public void setCreatetime(Date createtime) {
		this.createtime = createtime;
	}

	public Date getUpdatetime() {
		return updatetime;
	}

	public void setUpdatetime(Date updatetime) {
		this.updatetime = updatetime;
	}

	public Integer getTab() {
		return tab;
	}

	public void setTab(Integer tab) {
		this.tab = tab;
	}

	public Long getManagerId() {
		return managerId;
	}

	public void setManagerId(Long managerId) {
		this.managerId = managerId;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content == null ? null : content.trim();
	}

	/**
	 * 获取文章对应标签的字符串
	 * 
	 * @return
	 */
	public String getTagString() {
		StringBuffer str = new StringBuffer();
		if (tagList != null) {
			for (int i = 0; i < tagList.size(); i++) {
				if (i == tagList.size() - 1) {
					str.append(tagList.get(i).getTagname());
				} else {
					str.append(tagList.get(i).getTagname() + ",");
				}
			}
		}
		return str.toString();
	}

	/**
	 * 获取标题的简要信息(超过15个字符的省略)
	 * 
	 * @return
	 */
	public String getBriefTitle() {
		if (this.title.length() > 15) {
			return this.title.substring(0, 15) + "...";
		}
		return this.title;
	}
	
	/**
	 * 获取标题的简要信息(超过15个字符的省略)
	 * 
	 * @return
	 */
	public String getBriefTitle30() {
		if (this.title.length() > 30) {
			return this.title.substring(0, 30) + "...";
		}
		return this.title;
	}

	/**
	 * 获取时间字符串
	 * 
	 * @return
	 */
	public String getStringUpdatetime() {
		if(this.updatetime!=null){
			String dateStr = dateFormat.format(updatetime);
			return dateStr;
		}
		return null;
	}
}